import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { JwtModule } from '@nestjs/jwt';
import { PassportModule } from '@nestjs/passport';
import { ConfigModule, ConfigService } from '@nestjs/config';

// 修正实体的导入路径
import { User } from '../user/entities/user.entity';
import { UserLog } from '../user-log/entities/user-log.entity';
import { AuthService } from './services/auth.service';
import { AuthController } from './controllers/auth.controller';
import { JwtStrategy } from './strategies/jwt.strategy';
import { LocalStrategy } from './strategies/local.strategy';
// 修正 UserService 和 UserLogService 的导入路径
import { UserService } from '../user/services/user.service';
import { UserLogService } from '../user-log/services/user-log.service';

// 导入 UserLogModule
import { UserLogModule } from '../user-log/user-log.module';
// 导入 SecurityLogModule
import { SecurityLogModule } from '../security-log/security-log.module';

@Module({
  imports: [
    TypeOrmModule.forFeature([User, UserLog]),
    PassportModule,
    JwtModule.registerAsync({
      imports: [ConfigModule],
      useFactory: (configService: ConfigService) => {
        const secret = configService.get('jwt.secret');
        const expiresIn = configService.get('jwt.expiresIn');
        console.log('JWT Config:', { secret: secret ? '已配置' : '未配置', expiresIn });
        
        return {
          secret: secret || 'your-super-secret-jwt-key',
          signOptions: {
            expiresIn: expiresIn || '24h',
          },
        };
      },
      inject: [ConfigService],
    }),
    // 添加 UserLogModule 到 imports
    UserLogModule,
    // 添加 SecurityLogModule 到 imports
    SecurityLogModule,
  ],
  controllers: [AuthController],
  providers: [
    AuthService, 
    JwtStrategy, 
    LocalStrategy,
    // 直接添加 UserService 和 UserLogService 到 providers 中
    UserService,
    UserLogService,
  ],
  exports: [AuthService, JwtStrategy],
})
export class AuthModule {} 